from django.contrib import admin

# Register your models here.

from .models import (
    User, AEDEquipment, Knowledge, VolunteerActivity, UserAuthentication,
    ChatHistory, Question, Answer, Tag, Comment, Like, EquipmentKnowledge
)

# 注册 User 模型
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
    list_display = ('nickname', 'openid', 'phone', 'email', 'created_at')
    search_fields = ('nickname', 'openid', 'phone', 'email')
    list_filter = ('created_at', 'updated_at')

# 注册 AEDEquipment 模型
@admin.register(AEDEquipment)
class AEDEquipmentAdmin(admin.ModelAdmin):
    list_display = ('name', 'status', 'longitude', 'latitude', 'created_at')
    search_fields = ('name', 'status')
    list_filter = ('status', 'created_at')

# 注册 Knowledge 模型
@admin.register(Knowledge)
class KnowledgeAdmin(admin.ModelAdmin):
    list_display = ('title', 'category', 'created_at')
    search_fields = ('title', 'category')
    list_filter = ('category', 'created_at')

# 注册 VolunteerActivity 模型
@admin.register(VolunteerActivity)
class VolunteerActivityAdmin(admin.ModelAdmin):
    list_display = ('user', 'task', 'service_time', 'points', 'created_at')
    search_fields = ('task', 'user__nickname')
    list_filter = ('service_time', 'created_at')

# 注册 UserAuthentication 模型
@admin.register(UserAuthentication)
class UserAuthenticationAdmin(admin.ModelAdmin):
    list_display = ('user', 'auth_token', 'created_at')
    search_fields = ('user__nickname', 'auth_token')

# 注册 ChatHistory 模型
@admin.register(ChatHistory)
class ChatHistoryAdmin(admin.ModelAdmin):
    list_display = ('user', 'message', 'response', 'created_at')
    search_fields = ('message', 'response', 'user__nickname')
    list_filter = ('created_at',)

# 注册 Question 模型
@admin.register(Question)
class QuestionAdmin(admin.ModelAdmin):
    list_display = ('title', 'user', 'created_at', 'updated_at')
    search_fields = ('title', 'content', 'user__nickname')
    list_filter = ('created_at', 'updated_at')

# 注册 Answer 模型
@admin.register(Answer)
class AnswerAdmin(admin.ModelAdmin):
    list_display = ('question', 'user', 'is_accepted', 'created_at', 'updated_at')
    search_fields = ('content', 'user__nickname', 'question__title')
    list_filter = ('is_accepted', 'created_at', 'updated_at')

# 注册 Tag 模型
@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
    list_display = ('name', 'created_at')
    search_fields = ('name',)

# 注册 Comment 模型
@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('user', 'content', 'created_at')
    search_fields = ('content', 'user__nickname')
    list_filter = ('created_at',)

# 注册 Like 模型
@admin.register(Like)
class LikeAdmin(admin.ModelAdmin):
    list_display = ('user', 'created_at')
    search_fields = ('user__nickname',)
    list_filter = ('created_at',)

# 注册 EquipmentKnowledge 模型
@admin.register(EquipmentKnowledge)
class EquipmentKnowledgeAdmin(admin.ModelAdmin):
    list_display = ('equipment', 'knowledge', 'created_at')
    search_fields = ('equipment__name', 'knowledge__title')
    list_filter = ('created_at',)

